package com.gientech.redisDemo.redisController;

import com.gientech.redisDemo.utils.RedisUtils;
import io.lettuce.core.dynamic.domain.Timeout;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
public class RedisController {

    @Resource
    StringRedisTemplate stringRedisTemplate;

    @GetMapping("redis/setValue")
    public String setValue() {
        String key = "name";
        String value = "luxiaoyu";
        stringRedisTemplate.opsForValue().set(key, value, 10, TimeUnit.SECONDS);
//        stringRedisTemplate.opsForSet().add("username", "luxiaoyu", "haha");
//        RedisUtils redisUtils = new RedisUtils();
//
//        redisUtils.set(key, value, 10);


        return "set value";
    }

    @GetMapping("redis/getValue")
    public String getValue() {
        String key = "name";
        String value = stringRedisTemplate.opsForValue().get(key);
        return "get value：" + value;
    }
}
